package com.xiaoran.robot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaoran.robot.entity.Auth;
import com.xiaoran.robot.mapper.AuthMapper;
import com.xiaoran.robot.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AuthServiceImpl implements AuthService {
    @Autowired
    AuthMapper mapper;
    @Override
    public Integer addAuth(Auth auth) {
        return mapper.insert(auth);
    }

    @Override
    public Integer delAuth(Integer id) {
        return mapper.delete(new QueryWrapper<Auth>().eq("id", id));
    }

    @Override
    public boolean doAuth(String id, Integer type) {
        QueryWrapper<Auth> queryWrapper = new QueryWrapper<>();
        if (type == 1){
            // 好友
            queryWrapper.eq("qid", id);
        } else {
            // 群组
            queryWrapper.eq("gid", id);
        }
        return mapper.selectOne(queryWrapper) != null;
    }
}
